
<!-- THREE STEPS TO INSTALL SERVERDATE TO JAVASCRIPT:

  1.  Save the code in a file called "servertime.php"
  2.  Copy the coding into the HEAD of your HTML document
  3.  Add the last code into the BODY of your HTML document  -->

<!-- STEP ONE:  Paste this code in a file called "servertime.php"
 (without the quotes) and place it in the main directory of your site.
 Change mode to executable - chmod 755  -->


<?php

/* Copyright 2005 Emery Wooten - www.mresoftware.com
 This script is called from Javascript. It should be called before any
 JavaScripts that use the date.
 Place the statement below in the <head> section of your HTML page:
 <script type="text/javascript" src="servertime.php"></script>
*/

// Supress errors
error_reporting(0);

/* If your server is not in your time zone, adjust it here.  Mine is 1 hour East of me.
To use this variable, you will need to remove the "//".
// $myServerOffset = (+1) * 3600;

// Get server date
$mydate = date("U");

// Get Timezone offset
$myoffs = date("Z") - $myServerOffset;

// Adjust offsets for local machine
print "var tzoffset = $myoffs + (new Date().getTimezoneOffset()*60);";

// Set JavaScript variable to your server time as seen from client machine's location.
print "var servertimeOBJ=new Date(($mydate+tzoffset)*1000);";
?>


<!-- STEP TWO: Paste this code into the HEAD of your HTML document  -->

<HEAD>

<script language="JavaScript" src="servertime.php"></script>

<script type="text/javascript">
<!-- Begin
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Emery Wooten :: www.mresoftware.com */

// First thing, reference the variable.
var servertimeOBJ;

// Now check that it is set
if (servertimeOBJ != null){
	var myscriptTime = servertimeOBJ;
}

// If server time not passed, use client's time
else{
	var myscriptTime = new Date();
}

/* "myscriptTime" is a variable local to this script. Name it as you wish.
 After the above code is executed, this local variable is used for all date/time
 calculations performed by the script. If all works, this variable
 contains the server date as a proper JavaScript date object. */

// End -->
</script>

</HEAD>


<!-- STEP THREE: Copy this code into the BODY of your HTML document  -->


<BODY>

<script type="text/javascript">
<!-- Begin
  document.write(myscriptTime)
// End -->
</script>

<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size:  2.48 KB -->